<template>
	<view class="list">
		<view class="item" v-for="(item, idx) in list" :key="idx">
			<view class="left">
				<view class="circle"></view>
			</view>
			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<view class="content">
					<input class="text" v-model="item.content.value" v-if="item.content.type === 'text'">
					</input>
					<view class="image" v-if="item.content.type === 'image'">
						<u--image @click="previewImage(img.url)" mode="aspectFill" radius="14rpx" width="294rpx"
							height="200rpx" v-for="(img, idx2) in item.content.value" :key="idx2"
							:src="img.url ? img.url.replace(/\\/g,'/') : ''"></u--image>
						<!-- <image @click="previewImage(img.url)" mode="aspectFill" v-for="(img, idx2) in item.content.value" :key="idx2" :src="img.url ? img.url.replace(/\\/g,'/') : ''"></image> -->
					</view>
					<view class="video" v-if="item.content.type === 'video'">
						<video v-for="(video, idx2) in item.content.value" :key="idx2" :src="video.url"
							controls></video>
					</view>
					<view class="record" v-if="item.content.type === 'audio'">
						<view v-for="(audio, idx2) in item.content.value" :key="idx2">
							<view class="audio" @click="playAudio(audio.url)">
								<view class="audio-control">
									<text class="iconfont icon-24gf-play"
										v-if="audioState === 2 || audioState === 0"></text>
									<text class="iconfont icon-24gf-pause2" v-if="audioState === 1"></text>
								</view>
							</view>
							<view class="audio audio-stop" @click="stop()">
								<view class="audio-center"></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let innerAudioContext = '';
	export default {
		name: 'tineLine',
		data() {
			return {
				audioState: 0
			}
		},
		props: {
			list: {
				type: Array,
				default () {
					return [];
				}
			}
		},
		methods: {
			previewImage(url) {
				uni.previewImage({
					urls: [url],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			playAudio(url) {
				if (this.audioState === 0) {
					innerAudioContext = uni.createInnerAudioContext();
					innerAudioContext.autoplay = true;
					innerAudioContext.src = url;
					innerAudioContext.onPlay(() => {
						console.log('开始播放');
					});
					innerAudioContext.onError((res) => {
						console.log(res.errMsg);
						console.log(res.errCode);
					});
					this.audioState = 1;
				} else if (this.audioState === 1) {
					this.pause()
					this.audioState = 2;
				} else if (this.audioState === 2) {
					this.play()
					this.audioState = 1;
				}
			},
			play() {
				innerAudioContext.play();
			},
			pause() {
				innerAudioContext.pause();
			},
			stop() {
				innerAudioContext.stop();
				this.audioState = 2;
			},
		},
	}
</script>

<style lang="scss" scoped>
	.list {
		width: 100%;
		box-sizing: border-box;

		.item {
			width: 100%;
			min-height: 110rpx;
			@include clear();
			position: relative;

			&:last-child {
				.left {
					&::before {
						display: none;
					}
				}
			}

			.left {
				float: left;
				width: 20rpx;
				position: absolute;
				left: 0;
				top: 0;
				height: 100%;

				&::before {
					content: '';
					width: 1rpx;
					height: 100%;
					position: absolute;
					left: 10rpx;
					top: 20rpx;
					border-left: 1rpx dashed #0036df
				}

				.circle {
					width: 20rpx;
					height: 20rpx;
					background-color: #0036df;
					border: solid 1rpx #ffffff;
					border-radius: 50%;
				}
			}

			.right {
				float: left;
				margin-left: 45rpx;
				width: calc(100% - 20rpx - 25rpx);

				.title {
					line-height: 30rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #7f98ae;
					margin-bottom: 10rpx;
				}

				.content {
					width: 100%;
					margin-bottom: 40rpx;

					.text {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 30rpx;
						letter-spacing: 0rpx;
						color: #46464a;
					}

					.image {
						width: 100%;
						display: flex;
						justify-content: space-between;
						flex-wrap: wrap;

						/deep/ .u-fade-enter-active {
							background-color: rgba(0, 0, 0, 0) !important;
						}

						image {
							width: 294rpx;
							height: 200rpx;
							border-radius: 14rpx;
							margin-bottom: 30rpx;
						}
					}

					.video {
						width: 100%;
					}

					.record {
						.audio {
							width: 50rpx;
							height: 50rpx;
							background-color: #ffffff;
							border-radius: 50%;
							box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
							overflow: hidden;
							margin-right: 50rpx;
							float: left;

							.audio-center {
								margin-top: 13rpx;
								margin-left: 13rpx;
								border-radius: 50%;
								width: 24rpx;
								height: 24rpx;
								background-color: #ed451b;
							}

							.audio-control {
								width: 100%;
								height: 100%;
								position: relative;

								text {
									width: 30rpx;
									height: 30rpx;
									display: inline-block;
									position: absolute;
									top: 0;
									left: 0;
									right: 0;
									bottom: 0;
									margin: auto;
									font-size: 30rpx;
									color: #ed451b;
								}
							}

							.audio-center__on {
								animation: scale 2s infinite;
							}

							.audio-center__fin {
								background-color: rgba(0, 0, 0, 0.5);
								;
							}

							@keyframes scale {
								0% {
									transform: scale(1);
									opacity: 1;
								}

								50% {
									transform: scale(1.5);
									opacity: 0.5;
								}

								100% {
									transform: scale(1);
									opacity: 1;
								}
							}
						}

						.audio-stop {
							.audio-center {
								border-radius: 5rpx;
								background-color: #333;
							}
						}
					}
				}
			}
		}
	}
</style>
